package com.jsmile.cloud.tradecenter.order.repo;

import java.util.List;

import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jsmile.cloud.tradecenter.order.dao.OrderDiscountDao;
import com.jsmile.cloud.tradecenter.order.model.OrderDiscount;
import com.jsmile.mall.api.enums.JSmileCacheEnum;

import lombok.AllArgsConstructor;

@Component
@AllArgsConstructor
@Transactional(readOnly = true)
public class OrderDiscountSearchRepository extends ServiceImpl<OrderDiscountDao, OrderDiscount> {

    @Cacheable(value = JSmileCacheEnum.JSmileCacheName.oneMonth, key = "'discounts_'+#orderNo")
    public List<OrderDiscount> findByOrderNo(Long orderNo) {
        return this.baseMapper.selectList(new QueryWrapper<OrderDiscount>().lambda().eq(OrderDiscount::getOrderNo, orderNo));
    }

}
